package com.information.manage.basic.controller;

import com.information.manage.basic.common.result.Result;
import com.information.manage.basic.common.utils.RedisUtils;
import com.information.manage.basic.model.query.ClearRedisQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisUtils redisUtils;

    @PostMapping("/clear")
    public Result<String> clearRedis(@RequestBody ClearRedisQuery clearRedisQuery){
        if (clearRedisQuery.getIsAll()){
            // 全部清除
            redisUtils.flushCurrentDatabase();
        }else {
            String key = clearRedisQuery.getKey();
            if (StringUtils.isNotEmpty(key)){
                redisUtils.remove(key);
            }else {
                return Result.ok("未传入需要删除的key");
            }
        }
        return Result.ok("ok");
    }

}
